//
//  CDHAndZiYuanHeader.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/23.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "CDHAndZiYuanHeader.h"

@implementation CDHAndZiYuanHeader

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        [self initSubView];
        [self layout];
    }
    return self;
}
- (void)initSubView{
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.nameLabel];
    [self addSubview:self.fixButton];
    [self addSubview:self.backView];
    [_backView addSubview:self.leftButton];
    [_backView addSubview:self.leftImageView];
    [_backView addSubview:self.titleLabel];
    [_backView addSubview:self.detailLabel];
}
- (void)layout{
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@100);
        make.top.equalTo(@10);
        make.width.equalTo(@120);
        make.height.equalTo(@15);
    }];
    [_fixButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@0).offset(-100);
        make.centerY.equalTo(self->_nameLabel.mas_centerY);
        make.width.equalTo(@60);
        make.height.equalTo(@15);
    }];
    [_backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@100);
        make.top.equalTo(@40);
        make.right.equalTo(@0).offset(-100);
        make.height.equalTo(@50);
    }];
    [_leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.centerY.equalTo(self->_backView.mas_centerY);
        make.width.equalTo(@19);
        make.height.equalTo(@10);
    }];
    [_leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_leftButton.mas_right).offset(10);
        make.centerY.equalTo(self->_backView.mas_centerY);
        make.width.equalTo(@26);
        make.height.equalTo(@23);
    }];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_leftImageView.mas_right).offset(10);
        make.centerY.equalTo(self->_backView.mas_centerY);
        make.right.equalTo(self->_backView.mas_centerX);
        make.height.equalTo(@23);
    }];
    [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_backView.mas_centerX).offset(10);
        make.centerY.equalTo(self->_backView.mas_centerY);
        make.right.equalTo(self->_backView.mas_right).offset(-10);
        make.height.equalTo(@23);
    }];
}
- (UILabel *)nameLabel{
    if (!_nameLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text = @"标题";
        label.textColor = SELECTEDCOLOR;
        label.textAlignment = 0;
        label.font = [UIFont systemFontOfSize:14];
        _nameLabel = label;
    }
    return _nameLabel;
}
- (UIButton *)fixButton{
    if (!_fixButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"修改" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        [button setTitleColor:SELECTEDCOLOR forState:0];
        [button addTarget:self action:@selector(fixButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        _fixButton = button;
    }
    return _fixButton;
}
- (void)fixButtonClick:(UIButton *)sender{
    
}
- (UIView *)backView{
    if (!_backView) {
        UIView *view  = [[UIView alloc]init];
        view.backgroundColor = MAINBACKCOLOR;
        _backView = view;
    }
    return _backView;
}
- (UIButton *)leftButton{
    if (!_leftButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"arrow_down"] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
        _leftButton = button;
    }
    return _leftButton;
}
- (void)back:(UIButton *)sender{
    
}
- (UIImageView *)leftImageView{
    if (!_leftImageView ) {
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.image = [UIImage imageNamed:@"zy_collection_xjwjj"];
        _leftImageView  = imageView;
    }
    return _leftImageView;
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text = @"新概念 Lesson1";
        label.textColor = TITLECOLOR;
        label.textAlignment = 0;
        label.font = [UIFont systemFontOfSize:14];
        _titleLabel = label;
    }
    return _titleLabel;
}
- (UILabel *)detailLabel{
    if (!_detailLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text = @"文件：3  大小：82.5MB";
        label.textColor = TITLECOLOR;
        label.textAlignment = 0;
        label.font = [UIFont systemFontOfSize:12];
        _detailLabel = label;
    }
    return _detailLabel;
}
- (void)drawRect:(CGRect)rect{
    UIBezierPath *path = [[UIBezierPath alloc]init];
    [path moveToPoint:CGPointMake(self.frame.size.width-100, 39)];
    [path addLineToPoint:CGPointMake(100, 39)];
    [LINCOLOR set];
    [path stroke];
}
@end
